//
//  ALPS_TListTCell.m
//  Alps
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_TListTCell.h"

@implementation ALPS_TListTCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.smallView = [[UIImageView alloc] init];
        [self.contentView addSubview:_smallView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
        [self.contentView addSubview:_titleLabel];
        
        self.middleLabel = [[UILabel alloc] init];
        self.middleLabel.textColor = [UIColor grayColor];
        self.middleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_middleLabel];
        
        self.underLabel = [[UILabel alloc] init];
        self.underLabel.font = [UIFont systemFontOfSize:15];
        self.underLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_underLabel];
        
        self.arrowView = [[UIImageView alloc] init];
        self.arrowView.image = [UIImage imageNamed:@"xm_accessory"];
        [self.contentView addSubview:_arrowView];
        
        self.lineLabel = [[UILabel alloc] init];
        self.lineLabel.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:_lineLabel];
        
        
    }

    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.smallView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.contentView).offset(10);
        make.width.equalTo(80);
        make.height.equalTo(80);
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.height.equalTo(20);
        make.right.equalTo(self.contentView).offset(-30);
//        make.width.equalTo(250);
    }];
    
    [self.middleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.bottom).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.right.equalTo(self.contentView).offset(-30);
        make.height.equalTo(20);
//        make.width.equalTo(250);
    }];
    
    [self.underLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.middleLabel.bottom).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.right.equalTo(self.contentView).offset(-30);
        make.height.equalTo(20);
    }];
    
    [self.arrowView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(40);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(15);
        make.width.equalTo(15);
    }];
    [self.lineLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.underLabel.bottom).offset(4);
        make.left.equalTo(self.contentView).offset(100);
        make.width.equalTo(self.contentView.width);
        make.height.equalTo(1);
    }];
    
}

-(void)setModel:(ALPS_TListModel *)model
{
    if (_model != model) {
        _model = model;
        
        [self.smallView sd_setImageWithURL:[NSURL URLWithString:model.coverPath] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
        self.titleLabel.text = model.title;
        NSArray *array = self.model.firstKResults;
        self.middleLabel.text = [NSString stringWithFormat:@"1  %@",[array[0] objectForKey:@"title"]];
        self.underLabel.text = [NSString stringWithFormat:@"2  %@", [array[1] objectForKey:@"title"]];
        
    }


}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
